/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.velocityme.entity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;

/**
 *
 * @author rcrida
 */
@Entity
@NamedQueries( {
    @NamedQuery(name="findSprintByDate",
                query="SELECT o FROM Sprint o WHERE o.startDate < :startDate AND o.stopDate > :stopDate"),
    @NamedQuery(name="findSprintByPersonDate",
                query="SELECT o FROM Sprint o, IN (o.teamMembers) p WHERE o.startDate < :date AND o.stopDate > :date AND (o.scrumMaster = :person OR p = :person)")
})
public class Sprint extends Node {
    private static final long serialVersionUID = 1L;

    @Temporal(javax.persistence.TemporalType.DATE)
    private Date startDate;

    @Temporal(javax.persistence.TemporalType.DATE)
    private Date stopDate;

    @ManyToOne
    private Person scrumMaster;

    @ManyToMany
    private Collection<Person> teamMembers = new ArrayList<Person>();

    public void addTeamMember(Person person) {
        if (!teamMembers.contains(person)) {
            teamMembers.add(person);
        }
    }

    public void clearTeamMembers() {
        teamMembers.clear();
    }

    public Person getScrumMaster() {
        return scrumMaster;
    }

    public void setScrumMaster(Person scrumMaster) {
        this.scrumMaster = scrumMaster;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getStopDate() {
        return stopDate;
    }

    public void setStopDate(Date stopDate) {
        this.stopDate = stopDate;
    }

    public Collection<Person> getTeamMembers() {
        return teamMembers;
    }

    public void setTeamMembers(Collection<Person> teamMembers) {
        this.teamMembers = teamMembers;
    }


}
